//
//  SYToolView.swift
//  SYWeibo
//
//  Created by Saya on 16/4/12.
//  Copyright © 2016年 黄金果. All rights reserved.
//

import UIKit

class SYToolView: UIView {
    //设置数据
    var statusModel:SYCellStatusViewModel?{
        didSet{
            repostBtn.setTitle(statusModel?.repostCount, forState: .Normal)
            commentsBtn.setTitle(statusModel?.commentCount, forState: .Normal)
            zanBtn.setTitle(statusModel?.zanCount, forState: .Normal)
        }
    }
    
    
    //添加属性
    var repostBtn:UIButton!
    var commentsBtn:UIButton!
    var zanBtn:UIButton!
    
    var sepLineOne:UIView!
    var sepLineTwo:UIView!
    
    //自定义控件的入口
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.repostBtn = setUpToolButton("转发", iconName: "timeline_icon_retweet")
        self.commentsBtn = setUpToolButton("评论", iconName: "timeline_icon_comment")
        self.zanBtn = setUpToolButton("赞", iconName: "timeline_icon_like")
        
        self.sepLineOne = setUpSepLine()
        self.sepLineTwo = setUpSepLine()
        
        setUpUI()
    }
    
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")

    }
    
    private func setUpUI (){
        addSubview(repostBtn)
        addSubview(commentsBtn)
        addSubview(zanBtn)
        
        addSubview(sepLineOne)
        addSubview(sepLineTwo)
        
        repostBtn?.snp_makeConstraints(closure: { (make) -> Void in
            make.left.top.bottom.equalTo(self)
            make.width.equalTo(commentsBtn.snp_width)
        })
        commentsBtn?.snp_makeConstraints(closure: { (make) -> Void in
            make.top.bottom.equalTo(repostBtn)
            make.left.equalTo(repostBtn.snp_right)
            make.right.equalTo(zanBtn.snp_left)
            make.width.equalTo(zanBtn.snp_width)
            
        })
        zanBtn.snp_makeConstraints { (make) -> Void in
            make.right.top.bottom.equalTo(self)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        
        let width:CGFloat = 3 / UIScreen.mainScreen().scale
        sepLineOne.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(width)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.left.equalTo(repostBtn.snp_right)
            make.centerY.equalTo(repostBtn.snp_centerY)
        }
        
        //            make.height.equalTo(self.snp_height).multipliedBy(multiplied)
        
        sepLineTwo.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(width)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.left.equalTo(commentsBtn.snp_right)
            make.centerY.equalTo(repostBtn.snp_centerY)
        }
    }
    
    //此处不应该使用懒加载控件,而是创建一个方法比较合适
    private func setUpToolButton (text:String,iconName:String)->UIButton{
        let tempBtn = UIButton()
        tempBtn.setTitle(text, forState: .Normal)
        tempBtn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        tempBtn.setImage(UIImage(named: iconName), forState: .Normal)
        tempBtn.titleLabel?.font = UIFont.systemFontOfSize(12)
        tempBtn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        tempBtn.setBackgroundImage(UIImage(named: "timeline_card_bottom_line_highlighted"), forState: .Highlighted)
        tempBtn.sizeToFit()
        return tempBtn
    }
    
    //分割线
    private func setUpSepLine ()->UIView{
        let sepLine = UIView()
        sepLine.backgroundColor = UIColor.purpleColor()
        
        
        return sepLine
    }

}
